package com.situ.day2;

import org.junit.Test;

import java.util.Random;
import java.util.Scanner;

public class Demo {

    //junit java unit
    @Test
    public void test1() {
        //+     -     *     /    %
        int num1 = 3;
        int num2 = 5;
        int result = num1 + num2;
        System.out.println(result);
        System.out.println(num1 - num2);
        System.out.println(num1 * num2);
        System.out.println(num1 / num2);

        System.out.println(8 / 2);//4
        System.out.println(8 % 2);//0
        System.out.println(8 / 5);//1
        System.out.println(8 % 5);//3
    }

//    1、单独使用的时候，++、--在前后是没有差别的
//    2、被使用的时候，在前后是有差别的
    @Test
    public void test2() {
        int i = 0;
        i++;//i = i + 1
        i--;//i = i - 1
        System.out.println(i);//0
        ++i;
        --i;
        System.out.println(i);//0
        //i++被使用时候：先用后加
        System.out.println(i++);//0
        System.out.println(i);//1
        //++i被使用时候：先加后用
        System.out.println(++i);//2
    }

    //比较运算符：>   <    >=     <=    !=
    @Test
    public void test5() {
        int num1 = 3;
        int num2 = 5;
        boolean bool = num1 > num2;
        System.out.println(bool);//false
        System.out.println(num1 < num2);//true
        System.out.println(num1 <= num2);//true
        System.out.println(num1 != num2);//true
    }

//    &&：两边的结果都是true，结果才是true
//    ||：两边只要有一个是true，结果就是true
//    顺利毕业： true
//    1、平时成绩>60                  boolean(true)
//    &&   ||
//    2、四级成绩>400                boolean(true)
    @Test
    public void test55() {
        int score1 = 56;
        int score2 = 456;
        boolean bool = (score1 >= 60) && (score2 >= 400);
        System.out.println(bool);
    }

    @Test
    public void test66() {
        int num1 = 13;
        if (num1 > 5) {
            System.out.println("num1>5");
        } else {
            System.out.println("num1<=5");
        }
    }

//    >=90   <=100      优秀
//    >=80    <90       良好
//    >=70    <80       一般
//    >=60    <70      及格
//    <60              不及格
    @Test
    public void test666() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入成绩：");
        int score = scanner.nextInt();
        //int score = 79;
        if (score >= 90 && score <= 100) {
            System.out.println("优秀");
        } else if (score >= 80 && score < 90) {
            System.out.println("良好");
        } else if (score >= 70 && score < 80) {
            System.out.println("一般");
        } else if (score >= 60 && score < 70) {
            System.out.println("及格");
        } else {
            System.out.println("不及格");
        }
    }

//    三目运算符号：
//    语法：boolean ? 数1 ： 数2
    @Test
    public void test616() {
        int num1 = 13;
        int num2 = 5;
        int max = 0;
        if (num1 >= num2) {
            max = num1;
        } else {
            max = num2;
        }
        System.out.println(max);
    }

    @Test
    public void test6716() {
        int num1 = 13;
        int num2 = 5;
        //Math.max(3, 5);
        int max = num1 >= num2 ? num1 : num2;
        System.out.println(max);
    }

    @Test
    public void test67() {
        int count = 1;
        while (count <= 5) {
            System.out.println("HelloWorld");
            count++;
        }
    }

    @Test
    public void test667() {
        // i,j,k
        for (int i = 1; i <= 5; i++) {
            System.out.println("HelloWorld");
        }
    }

    //1、累加思想（1+2+3+... + 100）
    @Test
    public void test166() {
        int sum = 0;
        for (int i = 1; i <= 100; i++) {
            System.out.println(i);
            sum = sum + i;
            System.out.println("sum: " + sum);
        }
        System.out.println("sum: " + sum);
    }

    //2、统计思想，数一下符合条件的有多少个（计算1-100以内7的倍数的个数）
    @Test
    public void test99() {
        int count = 0;
        for (int i = 1; i <= 100; i++) {
            if (i % 7 == 0) {//除以7余数是0
                System.out.println(i);
                count++;//count = count + 1;
            }
        }
        System.out.println("count: " + count);
    }

//    continue、break：
//    continue：跳出本次循环，继续下一次循环
//    break：跳出离他最近的那层循环
    @Test
    public void test8() {
        for (int i = 1; i <= 5; i++) {
            if (i == 3) {
                continue;
            }
            System.out.println(i);
        }
    }

    @Test
    public void test80() {
        for (int i = 1; i <= 5; i++) {
            if (i == 3) {
                break;
            }
            System.out.println(i);
        }
    }

//    1、计算某年是不是闰年：
//    能被4整除，但是不能被100整除
//    ||
//    能被400整除
    @Test
    public void test123() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入年份：");
        int year = scanner.nextInt();
        if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
            System.out.println(year + "是闰年");
        } else {
            System.out.println(year + "不是闰年");
        }
    }

    @Test
    public void test45() {
        int num1 = 3;
        int num2 = 5;

        int temp = num1;
        num1 = num2;
        num2 = temp;

        System.out.println("num1: " + num1);
        System.out.println("num2: " + num2);
    }

    @Test
    public void test646() {
        Scanner scanner = new Scanner(System.in);
        Random random = new Random();
        //int value between zero (inclusive) and bound (exclusive)
        // [0,1000)+1
        // [1,1001)
        int rand = random.nextInt(1000) + 1;
        System.out.println("rand: " + rand);
        while (true) {
            System.out.println("猜吧");
            int guess = scanner.nextInt();
            if (guess > rand) {
                System.out.println("太大了");
            } else if (guess < rand) {
                System.out.println("太小了");
            } else {
                System.out.println("恭喜你，猜对了");
                break;
            }
        }
    }
}
